from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-15 14:12:05.541222
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 15, Aug, 2021
Time: 14:12:09
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.6444
Nobs: 384.000 HQIC: -46.2031
Log likelihood: 4127.66 FPE: 5.95377e-21
AIC: -46.5704 Det(Omega_mle): 4.72397e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.446092 0.095726 4.660 0.000
L1.Burgenland 0.110915 0.049676 2.233 0.026
L1.Kärnten -0.116732 0.024407 -4.783 0.000
L1.Niederösterreich 0.167423 0.106541 1.571 0.116
L1.Oberösterreich 0.116535 0.105307 1.107 0.268
L1.Salzburg 0.291960 0.051698 5.647 0.000
L1.Steiermark 0.014171 0.068541 0.207 0.836
L1.Tirol 0.123668 0.054072 2.287 0.022
L1.Vorarlberg -0.114323 0.048771 -2.344 0.019
L1.Wien -0.033581 0.094316 -0.356 0.722
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const -0.000111 0.226101 -0.000 1.000
L1.Burgenland -0.049156 0.117333 -0.419 0.675
L1.Kärnten 0.034992 0.057649 0.607 0.544
L1.Niederösterreich -0.251713 0.251646 -1.000 0.317
L1.Oberösterreich 0.550708 0.248732 2.214 0.027
L1.Salzburg 0.315115 0.122109 2.581 0.010
L1.Steiermark 0.113319 0.161891 0.700 0.484
L1.Tirol 0.301720 0.127717 2.362 0.018
L1.Vorarlberg -0.012730 0.115196 -0.111 0.912
L1.Wien 0.010407 0.222770 0.047 0.963
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.254643 0.048985 5.198 0.000
L1.Burgenland 0.096417 0.025420 3.793 0.000
L1.Kärnten -0.003268 0.012490 -0.262 0.794
L1.Niederösterreich 0.233505 0.054519 4.283 0.000
L1.Oberösterreich 0.155055 0.053888 2.877 0.004
L1.Salzburg 0.037338 0.026455 1.411 0.158
L1.Steiermark 0.009318 0.035074 0.266 0.790
L1.Tirol 0.074094 0.027670 2.678 0.007
L1.Vorarlberg 0.057167 0.024957 2.291 0.022
L1.Wien 0.086569 0.048263 1.794 0.073
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.192967 0.047855 4.032 0.000
L1.Burgenland 0.042959 0.024834 1.730 0.084
L1.Kärnten -0.006752 0.012202 -0.553 0.580
L1.Niederösterreich 0.123345 0.053261 2.316 0.021
L1.Oberösterreich 0.312890 0.052645 5.943 0.000
L1.Salzburg 0.102103 0.025845 3.951 0.000
L1.Steiermark 0.138354 0.034265 4.038 0.000
L1.Tirol 0.076841 0.027032 2.843 0.004
L1.Vorarlberg 0.055230 0.024381 2.265 0.023
L1.Wien -0.038907 0.047150 -0.825 0.409
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.210608 0.095616 2.203 0.028
L1.Burgenland -0.061501 0.049619 -1.239 0.215
L1.Kärnten -0.036627 0.024379 -1.502 0.133
L1.Niederösterreich 0.081802 0.106418 0.769 0.442
L1.Oberösterreich 0.198011 0.105186 1.882 0.060
L1.Salzburg 0.264876 0.051639 5.129 0.000
L1.Steiermark 0.073603 0.068462 1.075 0.282
L1.Tirol 0.125821 0.054010 2.330 0.020
L1.Vorarlberg 0.115602 0.048715 2.373 0.018
L1.Wien 0.031932 0.094207 0.339 0.735
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.031541 0.074753 0.422 0.673
L1.Burgenland 0.027155 0.038792 0.700 0.484
L1.Kärnten 0.050433 0.019060 2.646 0.008
L1.Niederösterreich 0.197921 0.083199 2.379 0.017
L1.Oberösterreich 0.345570 0.082235 4.202 0.000
L1.Salzburg 0.048170 0.040372 1.193 0.233
L1.Steiermark -0.003306 0.053524 -0.062 0.951
L1.Tirol 0.115981 0.042225 2.747 0.006
L1.Vorarlberg 0.062165 0.038086 1.632 0.103
L1.Wien 0.125664 0.073652 1.706 0.088
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181320 0.091111 1.990 0.047
L1.Burgenland 0.022623 0.047281 0.478 0.632
L1.Kärnten -0.057679 0.023231 -2.483 0.013
L1.Niederösterreich -0.116110 0.101405 -1.145 0.252
L1.Oberösterreich 0.192651 0.100231 1.922 0.055
L1.Salzburg 0.031559 0.049206 0.641 0.521
L1.Steiermark 0.300107 0.065237 4.600 0.000
L1.Tirol 0.494816 0.051466 9.615 0.000
L1.Vorarlberg 0.065619 0.046420 1.414 0.157
L1.Wien -0.111788 0.089769 -1.245 0.213
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.164785 0.099301 1.659 0.097
L1.Burgenland -0.003522 0.051531 -0.068 0.946
L1.Kärnten 0.062604 0.025319 2.473 0.013
L1.Niederösterreich 0.192068 0.110519 1.738 0.082
L1.Oberösterreich -0.121286 0.109240 -1.110 0.267
L1.Salzburg 0.244898 0.053629 4.567 0.000
L1.Steiermark 0.153346 0.071100 2.157 0.031
L1.Tirol 0.052826 0.056091 0.942 0.346
L1.Vorarlberg 0.121470 0.050592 2.401 0.016
L1.Wien 0.135950 0.097838 1.390 0.165
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.493870 0.053907 9.162 0.000
L1.Burgenland -0.016030 0.027974 -0.573 0.567
L1.Kärnten -0.009563 0.013745 -0.696 0.487
L1.Niederösterreich 0.197993 0.059997 3.300 0.001
L1.Oberösterreich 0.262043 0.059302 4.419 0.000
L1.Salzburg 0.021413 0.029113 0.736 0.462
L1.Steiermark -0.026017 0.038598 -0.674 0.500
L1.Tirol 0.068745 0.030450 2.258 0.024
L1.Vorarlberg 0.058599 0.027465 2.134 0.033
L1.Wien -0.048752 0.053113 -0.918 0.359
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.018595 0.066270 0.137029 0.125262 0.035974 0.066580 -0.002337 0.184213
Kärnten 0.018595 1.000000 -0.055938 0.128782 0.045211 0.069003 0.457842 -0.093848 0.098060
Niederösterreich 0.066270 -0.055938 1.000000 0.290679 0.090857 0.273953 0.014338 0.148120 0.255444
Oberösterreich 0.137029 0.128782 0.290679 1.000000 0.174955 0.294654 0.164097 0.119928 0.135266
Salzburg 0.125262 0.045211 0.090857 0.174955 1.000000 0.128968 0.050699 0.109358 0.050826
Steiermark 0.035974 0.069003 0.273953 0.294654 0.128968 1.000000 0.127303 0.087328 -0.023952
Tirol 0.066580 0.457842 0.014338 0.164097 0.050699 0.127303 1.000000 0.038528 0.121382
Vorarlberg -0.002337 -0.093848 0.148120 0.119928 0.109358 0.087328 0.038528 1.000000 -0.047887
Wien 0.184213 0.098060 0.255444 0.135266 0.050826 -0.023952 0.121382 -0.047887 1.000000